#include <bits/stdc++.h>
#define int long long
#define rg register
#define pc putchar
#define gc getchar
#define pf printf
#define space pc(' ')
#define enter pc('\n')
#define me(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define FOR(i,k,n,p) for(rg int i(k) ; i <= n ; i += p)
#define ROF(i,k,n,p) for(rg int i(k) ; i >= n ; i -= p)
using namespace std;
const int N = 1e5+5 ;
const int INF = 1e17+7 ;
int n,li,ans = INF ;
int mi[N],mn[N] ;
struct P{int x,y ;}a[N] ;
inline double Time()
{
	return (double)clock()/CLOCKS_PER_SEC;
}
inline void read(int &x)
{
	x = 0 ;rg int f(0) ; rg char c(gc()) ;
	while(!isdigit(c)) f |= (c=='-'),c = gc() ;
	while(isdigit(c)) x = (x<<1)+(x<<3)+(c^48),c = gc() ;
	x = (f?-x:x) ;
}
int stk[30],tp ;
inline void print(int x){
	if(x < 0) pc('-'),x = -x ;
	do stk[++tp] = x%10,x /= 10 ; while(x) ;
	while(tp) pc(stk[tp--]^48) ;
}
inline int cmp(P x,P y)
{
	return x.y < y.y ;
}
signed main()
{
    freopen("boast.in","r",stdin) ;
    freopen("boast.out","w",stdout) ;
 	read(n) ;
 	FOR(i,1,n,1) read(a[i].x),read(a[i].y) ;
 	sort(a+1,a+1+n,cmp) ;
	li = INF ;
	FOR(i,1,n,1)
    {
    	mi[i] = a[i].x+li+a[i].y ;
    	li = min(li,a[i].x) ;
	}
	li = INF ;
	FOR(i,1,n,1)
	{
		mn[i] = li+a[i].x+a[i].y ;
		li = min(mi[i],li),ans = min(ans,mn[i]) ;
	}
	print(ans) ;
	return 0;
}


